package cjq.demo.jvm;

/**
 * Created by Administrator on 2016/4/13.
 */
public class CanReliveObj {
    public static CanReliveObj obj ;

    protected void finalize() throws Throwable{
        super.finalize();
        System.out.println("CanReliveObj finalize called");
        obj = this;
    }

    public String toString(){
        return "I am CanReliveObj";
    }

    public static void main(String[] args) throws InterruptedException{
        obj = new CanReliveObj();
        obj = null;
        System.gc();
        Thread.sleep(1000);

        if(obj == null){
            System.out.println("obj is null");
        }else{
            System.out.println("obj is able");
        }

        System.out.println("the second time gc");
        obj = null;
        System.gc();
        Thread.sleep(1000);

        if(obj == null){
            System.out.println("obj is null");
        }else{
            System.out.println("obj is able");
        }
    }
}
